#include"thread.h"
#include"threadpool.h"
#include<iostream>
#include<thread>
#include<unistd.h>
using ULong = unsigned long long ;
class MyTask :public Task
{
  public:
  MyTask(int begin ,int end):begin_(begin),end_(end){}
     Any run()
     {
       ULong sum =0;
       for(int i=begin_;i<=end_;++i)
       {
        sum += i;
       }
        return sum;
     }
 private:
  int begin_;
  int end_;

};
int main()
{
  ThreadPool threadpool;
  threadpool.Start(4);

 Result res1= threadpool.SubmitTask(std::make_shared<MyTask>(0,10000));
 Result res2= threadpool.SubmitTask(std::make_shared<MyTask>(10001,20000));
 Result res3= threadpool.SubmitTask(std::make_shared<MyTask>(20001,30000));
 Result res4= threadpool.SubmitTask(std::make_shared<MyTask>(30001,40000));
 Result res5= threadpool.SubmitTask(std::make_shared<MyTask>(40001,50000));
 Result res6= threadpool.SubmitTask(std::make_shared<MyTask>(50001,60000));
 Result res7= threadpool.SubmitTask(std::make_shared<MyTask>(60001,70000));
 ULong sum1 = res1.get().cast_<ULong>();
 ULong sum2 = res2.get().cast_<ULong>();
 ULong sum3 = res3.get().cast_<ULong>();
 ULong sum4 = res4.get().cast_<ULong>();
 ULong sum5 = res5.get().cast_<ULong>();
 ULong sum6 = res6.get().cast_<ULong>();
 ULong sum7 = res7.get().cast_<ULong>();
 ULong sum =0;
 for(int i=0;i<=70000;++i)
 {
  sum+=i;
 }
  std::cout<<sum1+sum2+sum3+sum4+sum5+sum6+sum7<<std::endl;
  std::cout<<sum<<std::endl;
  exit(0);

}